package com.zygh.policeasset.listenter;

import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.zygh.policeasset.component.SpringJobBeanFactory;
import com.zygh.policeasset.mapper.AssetsLifeCycleMapper;
import com.zygh.policeasset.pojo.imports.BasicsImport;
import com.zygh.policeasset.service.AssetsService;
import com.zygh.policeasset.utils.ImportListenerUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;

/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/listenter/BasicsImportListener.class */
public class BasicsImportListener extends AnalysisEventListener<BasicsImport> {
    private static final Logger log = LoggerFactory.getLogger(BasicsImportListener.class);
    AssetsService assetsService;
    String projectNo;
    String inputNum;
    String sectionName;
    Integer sectionId;
    Integer companyId;
    String type;
    Map<Integer, Object> map;
    Integer selfBuilt;
    String time;
    private static final int BATCH_COUNT = 30000;
    ImportListenerUtil importListenerUtil = (ImportListenerUtil) SpringJobBeanFactory.getBean(ImportListenerUtil.class);
    AssetsLifeCycleMapper assetsLifeCycleMapper = (AssetsLifeCycleMapper) SpringJobBeanFactory.getBean(AssetsLifeCycleMapper.class);
    List<BasicsImport> list = new ArrayList();

    public BasicsImportListener(AssetsService assetsService, String projectNo, String inputNum, String sectionName, Integer sectionId, Integer companyId, String type, Map<Integer, Object> map, Integer selfBuilt, String time) {
        this.assetsService = assetsService;
        this.projectNo = projectNo;
        this.inputNum = inputNum;
        this.sectionName = sectionName;
        this.sectionId = sectionId;
        this.companyId = companyId;
        this.type = type;
        this.map = map;
        this.selfBuilt = selfBuilt;
        this.time = time;
    }

    public void invoke(BasicsImport data, AnalysisContext context) {
        this.list.add(this.importListenerUtil.checkDataBasics(data, this.projectNo, this.inputNum, this.sectionName, this.sectionId, this.companyId, this.type, this.selfBuilt, Integer.valueOf(context.readRowHolder().getRowIndex().intValue() + 1), this.time));
        if (this.list.size() >= 30000) {
            saveData(context);
            this.list.clear();
        }
    }

    @Override // com.alibaba.excel.read.listener.ReadListener
    public void doAfterAllAnalysed(AnalysisContext context) {
        saveData(context);
        log.info("所有数据解析完成！");
    }

    private void saveData(AnalysisContext context) {
        log.info("核对二维码编号数量");
        this.importListenerUtil.checkDataBasicsQrcode(this.list, this.projectNo, this.sectionId, Integer.valueOf(context.readRowHolder().getRowIndex().intValue() + 1));
        log.info("{}条数据，开始存储数据库！", Integer.valueOf(this.list.size()));
        if (!CollectionUtils.isEmpty(this.list)) {
            for (int i = 0; i < this.list.size(); i++) {
                this.assetsService.addBasics(this.list.get(i));
                this.assetsLifeCycleMapper.add(this.list.get(i).getId(), 0, DateUtil.now(), Integer.valueOf(Integer.parseInt(this.list.get(i).getUserId())));
                if (this.map.containsKey(Integer.valueOf(i))) {
                    this.importListenerUtil.addimage(this.list.get(i).getId(), this.map.get(Integer.valueOf(i)).toString(), this.list.get(i).getPactName(), this.projectNo, "jc");
                }
            }
        }
        log.info("存储数据库成功！");
    }
}